<?php
namespace Index\Controller;
use Think\Controller;
class IndexController extends Controller {

    public function index(){
        $this->display();
    }

    public function product()
    {
        $this->display();
    }

    public function service()
    {
        $this->display();
    }

    public function about()
    {
        $this->display('our');
    }

    public function test()
    {
        if(IS_AJAX){
            $data = I('post.');
            $model = M('test');
            $res = $model->add($data);
            if($res){
                $this->ajaxReturn(['status'=>'success','msg'=>'免费申请已提交','data'=>$data]);
            }else{
                $this->ajaxReturn(['status'=>'error','msg'=>'申请出错','data'=>$data]);
            }
        }
        $this->display('mianfei');
    }

    public function login()
    {
        $this->display();
    }

    /**
     * @name
     * @desc
     * @auther ycp
     */
    public function news(){
        $catId = I('get.cat_id');
        $id = I('get.id');
        if($catId){
            //分类下的文章
            $Model =M('company_article');
            $article_data = $Model->where([
                'cat_id' => ['eq',$catId]
            ])->select();
//            var_dump($article_data);
            //分类
            $catModel =M('company_category');
            $catData = $catModel->select();
            $this->assign('catData',$catData);
            $this->assign('article_data',$article_data);
            $this->display();
            exit();
        }
        if($id){

        }
        $catModel =M('company_category');
        $catData = $catModel->select();
        $catId = $catModel->find();
        //分类下的文章
        $Model =M('company_article');
        $article_data = $Model->where([
            'cat_id' => ['eq',$catId['id']]
        ])->select();

       $this->assign('catData',$catData);
       $this->assign('article_data',$article_data);
        $this->display();
    }

    public function newsDetail()
    {
        $catModel =M('company_category');
        $catData = $catModel->select();
        $catId = $catModel->find();
        //分类下的文章
        $Model =M('company_article');
        $article_data = $Model->where([
            'cat_id' => ['eq',$catId['id']]
        ])->select();
        $id = I('get.id');
        if($id){
            $article_detail  = $Model->find($id);
            $this->assign('article_detail',$article_detail);
        }
        $this->assign('catData',$catData);
        $this->display();
    }
}
